$(function () {
    $("#page").load("/html/page.html");
});
function searchAll() {
    let data = {
        name: $("#name").val(),
        leader: $("#leader").val(),
        startEstablishedTime:$("#startEstablishedTime").val(),
        endEstablishedTime:$("#endEstablishedTime").val(),
        pageSize: $.trim($("#pageSize").val()),
        pageNum: $.trim($("#pageNum").val()),
    }
    let result = myAjax('/group/selectAll', "post", data)
    show(result.list);
    $("#pageCount").html(result.number);
}

function show(data) {
    let html = "";
    for (let i = 0; i < data.length; i++) {
        html += '   <tr> ' +
            '  <td><input type="checkbox" name="isCheck" value="'+data[i].id+'">' + data[i].id + '</td>\n' +
            '        <td>' + data[i].name + '</td>\n' +
            '        <td>' + data[i].leader + '</td>\n' +
            '        <td>' + data[i].establishedTime + '</td>\n' +
            '        <td><input type="button" style="width: 60px;border-radius: 5px;' +
            'background-color: red" value="删除" onclick="del(' + data[i].id + ')">' +
            '         <input type="button" style="width: 60px;border-radius: 5px;' +
            'background-color: #5FB878" value="修改" onclick="edit('+ data[i].id +',`'+data[i].name+'`)"></td>' +
            '    </tr>';
    }
    $("#findAll").html(html);
}
function del(id) {
    layer.confirm("删除后会解散该组成员，确定删除吗？","",function () {
        let result = myAjax("/group/delete", "get", {id: id})
        if (result === 1) {
            layer.msg("删除成功");
            searchAll();
        }
    });
}
//点击修改按钮进行页面弹出，传递两个参数，一个小组id一个小组名字，然后动态赋值给弹出页面，后面添加成员要用到。
layui.use('layer');
function edit(id,name) {
    sessionStorage.setItem("groupId",id);
    //弹出一个页面层
    let html = "<span id='group-name-edit'>"+name+"</span>"
    layer.open({
        type: 2,
        anim:3,
        title:'编辑'+html+'',
        area: ['600px', '500px'],
        shadeClose: true, //点击遮罩关闭
        content: ['/html/groupEdit.html','no'],
    })
}